package com.cxhome.cxinfox.sms;

import com.cxhome.cxinfox.provider.ProviderService;
import com.jfinal.plugin.activerecord.Page;
import com.traffic.managent.annotation.ControllerBind;
import com.traffic.managent.base.CxBaseController;
import com.traffic.managent.util.SQLUtils;
import com.traffic.managent.util.StringUtils;

/**
 * 短信管理
 * 
 * @author Guoxing
 *
 */
@ControllerBind(controllerKey = "/system/sms")
public class SmsController extends CxBaseController {

	private static final String path = "/pages/system/sms/sms_";

	/**
	 * 默认方法
	 */
	public void index() {
		list();
	}

	/**
	 * 查询短息列表
	 */
	public void list() {
		Sms model = getModelByAttr(Sms.class);

		StringBuilder orderSql = new StringBuilder("");
		// 排序
		String orderBy = getBaseForm().getOrderBy();
		if (StringUtils.isEmpty(orderBy)) {
			orderSql.append(" order by  sendTime desc ");
		} else {
			orderSql.append(" order by ").append(orderBy.trim());
		}

		Page<Sms> page = SmsService.service.paginate(model, getPaginator(), orderSql);

		setAttr("page", page);
		setAttr("attr", model);
		render(path + "list.html");
	}
//	public void list() {
//		Sms model = getModelByAttr(Sms.class);
//		
//		SQLUtils sql = new SQLUtils(" from cx_sms where 1 = 1  ");
//		
//		if (model.getAttrValues().length != 0) {
//			sql.whereLike("phoneId", model.getStr("phoneId"));
//			sql.whereEquals("flag", model.getStr("flag"));
//		}
//		
//		// 排序
//		String orderBy = getBaseForm().getOrderBy();
//		if (StringUtils.isEmpty(orderBy)) {
//			sql.append(" order by  sendTime desc ");
//		} else {
//			sql.append(" order by ").append(orderBy);
//		}
//		
//		Page<Sms> page = Sms.dao.paginate(getPaginator(), "select * ", sql.toString().toString());
//		
//		setAttr("page", page);
//		setAttr("attr", model);
//		render(path + "list.html");
//	}

}
